<?
/**
 * 	The user class.
 *
 *	@copyright	2010 - oneDot only<br>
 *  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.<br>
 *  The content is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.  see the GNU General Public License for more details.
 *
 *	@author		Koen Betsens <we@onedotonly.be>
 *  @package	Global
 */

/**
 * The user class.
 *
 * The user class turns user database rows into more friendly User objects. The object handles the creation, data retreival and data editing - inclusive all referential, media and text connected to it. 
 * Since the Engine structure is object centric, most object handling should happen with this User class.  
 *
 * <code>
 * local | global $User = new USER( ID )
 * </code>
 *
 * @package		Global
 *
 * @return		Object	general OBJECT
 */
class USER extends OBJECT {

	/**
	 * The user ID
	 *
	 * @var	integer
	 */
	public $id;
	
	/**
	 * The user "" type string
	 *
	 * @var	string
	 */
	public $type = "user";

	/**
	 * Constructs the User object
	 *
	 * @todo	Remove $vars.
	 *
	 * @param 	mixed		$type_or_vars	string type or arry | object with variables
	 * @param 	int			$id				The object ID, incase not yet declared in $type_or_vars. Incase empty, it defaults to the most recent object of that type (or creation of a new object)
	 * @param 	boolean 	$create_new		If true, a new Object of the given type is created. Defaults to false. 
	 * @param 	mixed 		$vars			Deprecated in favour of $type_or_vars, should be deleted.
	 * @return	object
	 */
	function __construct( $id = 0, $vars = false, $is_new = 0 ) {
		global $DB;
		
		if( is_array( $vars ) || is_object( $vars ))

				$this->_addvars( $vars );

#		Create new
		if( $is_new )
			$this->create( $this->type, false, 0, $vars );

#		Load assigned object or most recent			
		else
			$this->load( $this->type, $this->id = ( int ) $id );

#		Set up extended Class
#		$this->social = new USER_SOCIAL( $this->type, $this->id );
	}
	
	
	public function load( $type, $id ) {
		global $DB;
		
#		Get DB row & decode meta
		$this->values = $DB->get( $type, ( $id )? "ID=" . $DB->smartq( $id, "int" ) : "active order by ID desc" );
		$this->values [ 'meta' ] = json_decode( $this->values[ 'meta' ]);

		return $this->values;
	}
	
		
	
	


}


?>